<?php

namespace App\Http\Requests\Admin\AdminCoupon;

use App\Http\Requests\Request;

class CouponStoreRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * 验证规则
     *
     * @return array
     */
    public function rules()
    {
        $rules = [
            'name' => 'required',
            'value' => 'required|numeric',
            'amount' => 'required|numeric',
            'limit_fir'=>'required',
            'type'=>'required',
            'use_id_str'=>'required_if:type,2|required_if:type,3|required_if:type,4|required_if:type,5',
            'start_time'=>'required|date',
            'end_time'=>'required|date|after:start_time',
            //'use_id_str'=>'required',
        ];


        /*$eorder =  [
           'ieType' => 'required|in:I,E',
           'stockFlag' => 'required|in:1,2',
           'batchNumbers' => 'required',
           'tradeCountryCiq' => 'required',
           'tradeCountryCus' => 'required',
           'packageTypeCiq' => 'required',
           'packageTypeCus' => 'required',
           'currencyCiq' => 'required',
           'currencyCus' => 'required',
           'unitCiq' => 'required',
           'unitCus' => 'required',
           'originCountryCiq' => 'required',
           'originCountryCus' => 'required',
           'weight' => 'required',
           'transportationWay' => 'required',
           'shipCode' => 'required',
        ];

        $type = $this->get('type');

        if ($type){
            $rules = array_merge($rules,$eorder);
        }*/


        return $rules;


    }

    /**
     * 验证信息
     * @return array
     */

    public function messages()
    {
        return [
            'name.required' => '请填写优惠券名称',
            'value.required'=>'请填写优惠券面值',
            'amount.required'=>'请填写优惠券发行数量',
            'limit_fir.required'=>'请填写优惠券满减规则',
            'type.required'=>'请填写优惠券使用类型',
            'use_id_str.required_if'=>'请选择值',
            'start_time.required'=>'请填写优惠券可用的开始时间',
            'end_time.required'=>'请填写优惠券可用的结束时间',
            //'use_id_str.required'=>'请选择类型的值',

            'value.numeric'=>'优惠券面值必须为数字',
            'amount.numeric'=>'发行数量必须为数字',

            'start_time.date'=>'开始时间必须为时间格式',
            'end_time.date'=>'结束时间必须为时间格式',
            'end_time.after'=>'结束时间必须大于开始时间',


        ];
    }
}//end class
